package cn.itcast.controller;

import cn.itcast.dataobject.Member;
import cn.itcast.service.MemberService;
import cn.itcast.utils.ResultVOUtil;
import cn.itcast.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: wangxg
 * @date: 2019-06-22 05:18
 **/

@RestController
@Api(description = "学员管理")
@RequestMapping("/admin/ucenter/member")
public class AdminMemberController {

    @Autowired
    private MemberService memberService;

    @ApiOperation(value = "返回所有学员列表")
    @GetMapping
    public ResultVO list() {
        List<Member> memberList = memberService.list();
        return ResultVOUtil.success(memberList);
    }

    @ApiOperation(value = "根据id删除学员")
    @DeleteMapping(value = "{memberId}")
    public ResultVO deleteById(@ApiParam(name = "memberId", value = "学员id", required = true)
                              @PathVariable Long memberId) {
        memberService.removeById(memberId);
        return ResultVOUtil.success();
    }

    @ApiOperation(value = "注册学员", notes = "updateTime,createTime无需添加，这是前台系统用户的注册功能，前提是用户已经接收了验证码")
    @PostMapping
    public ResultVO register(
            @ApiParam(name = "member", value = "学员对象", required = true)
            @RequestBody Member member) {
        memberService.save(member);
        return ResultVOUtil.success();
    }
}
